<?php

namespace apiend\modules\user\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\user\models\FollowForm;
use apiend\modules\user\models\FollowTeacherSearch;
use apiend\modules\user\models\FollowSchoolSearch;
use apiend\models\User;
use common\models\user\UserMeta;

/**
 * 教师检索用户接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class SearchController extends Controller {

    public $modelClass = 'apiend\modules\user\models\UserSearch';

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            'index' => ['GET'],
        ];
    }

    /**
     * 关注的教师列表
     * @inheritdoc
     */
    public function actionIndex() {
        $userid = $this->token->user_id;
        $user = UserMeta::findOne($userid);
        if (!$user->role_id) {
            return [];
        }
        $mobile = Yii::$app->request->get('mobile');
        if (!$mobile) {
            return [];
        }
        $entra = Yii::$app->security->generatePrivateKey($mobile);

        return User::find()->where(['mobile' => $entra])->all();
    }

}
